//
//  CheckCarViewController.m
//  CarTown
//
//  Created by 熊浩 on 15/8/28.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "CheckCarViewController.h"
#import "HYSegmentedControl.h"
#import "BottomBar.h"
#import "CheckedTableViewController.h"
#import "CheckIngTableViewController.h"
#import "CheckAllTableViewController.h"
#import "NoCheckTableViewController.h"
@interface CheckCarViewController ()<UIScrollViewDelegate,HYSegmentedControlDelegate,BottomBarBtnClickDelegate>
{
    BOOL _isedting;
}
@property (nonatomic,strong) HYSegmentedControl *hysegment;
@property (nonatomic,strong) BottomBar *toolbar;
@property (nonatomic,strong) BottomBar *secodebar;
@property (nonatomic,strong) UIScrollView *scrollview;

@end

@implementation CheckCarViewController
#pragma 类实例化方法
+(instancetype)Viewcontroller{
    CheckCarViewController *chvc=[[CheckCarViewController alloc]init];
    chvc.hidesBottomBarWhenPushed=YES;
    return chvc;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets=NO;
    self.hysegment=[[HYSegmentedControl alloc]initWithOriginY:120 Titles:@[@"全部车源",@"待申请验车",@"已申请",@"已验完的车"] delegate:self];
    self.view.backgroundColor=bgGarycolor;
    [self.view addSubview:self.hysegment];
    self.navigationItem.title=@"验车管理";
    [self setupview];
    [self setupcontroller];
    // Do any additional setup after loading the view.
}

-(void)hySegmentedControlSelectAtIndex:(NSInteger)index{
    
    [self.scrollview setContentOffset:CGPointMake(XHScreenwidth*index, 0) animated:YES];
    
    
}
-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}


- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    CGFloat x=scrollView.contentOffset.x;
    NSLog(@"%f",x);
    int  pageindex=x/XHScreenwidth;
   
        [self.hysegment changeSegmentedControlWithIndex:pageindex];
    
    
}


-(void)setupcontroller{
    CheckAllTableViewController *all=[CheckAllTableViewController ViewController];
    all.view.frame=CGRectMake(0, 0, XHScreenwidth, XHScreenheight-156);
    all.view.backgroundColor=bgGarycolor;
    [self.scrollview addSubview:all.view];
    [self addChildViewController:all];
    NoCheckTableViewController *no=[NoCheckTableViewController ViewController];
    no.view.frame=CGRectMake(XHScreenwidth, 0, XHScreenwidth, XHScreenheight-156);
    no.view.backgroundColor=bgGarycolor;
    [self.scrollview addSubview:no.view];
    [self addChildViewController:no];
    CheckIngTableViewController *checking=[CheckIngTableViewController ViewController];
    checking.view.frame=CGRectMake(XHScreenwidth*2, 0, XHScreenwidth, XHScreenheight-156);
    checking.view.backgroundColor=bgGarycolor;
    [self.scrollview addSubview:checking.view];
    [self addChildViewController:checking];
    CheckedTableViewController *checked=[CheckedTableViewController ViewController];
    checked.view.frame=CGRectMake(XHScreenwidth*3, 0, XHScreenwidth, XHScreenheight-156);
    checked.view.backgroundColor=bgGarycolor;
    [self.scrollview addSubview:checked.view];
    [self addChildViewController:checked];
    self.scrollview.delegate=self;
    BottomBar *bar=[[BottomBar alloc]initWithBtnTitleArray:@[@"申请验车"] WithDelegate:self:YES];
    [bar addInView:self.scrollview];
    bar.x=XHScreenwidth;
    bar.ishwopost=NO;
    self.toolbar=bar;
    bar.tag=0;
    BottomBar *downbar=[[BottomBar alloc]initWithBtnTitleArray:@[@"取消申请"] WithDelegate:self :YES];
    downbar.x=XHScreenwidth*2;
    [downbar addInView:self.scrollview];
    downbar.ishwopost=NO;
    self.secodebar=downbar;
    downbar.tag=1;
    
}
-(void)BottomBar:(BottomBar *)bottombar otherbtnClick:(NSInteger)index{
    NSLog(@"%ld",bottombar.tag);
}

-(void)rightclick{
    _isedting=!_isedting;
    [self setupRight:_isedting];
    
    
}
-(void)setupRight:(BOOL)iseidting{
    if (iseidting) {
        UIBarButtonItem *rightitem=[[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(rightclick)];
        [self.toolbar show];
         [self.secodebar show];
        self.navigationItem.rightBarButtonItem=rightitem;
        
    }else{
        [self.toolbar hide];
        [self.secodebar hide];
        self.toolbar.btnenable=NO;
        self.secodebar.btnenable=NO;
        UIBarButtonItem *rightitem=[[UIBarButtonItem alloc]initWithTitle:@"编辑" style:UIBarButtonItemStyleDone target:self action:@selector(rightclick)];
        
        self.navigationItem.rightBarButtonItem=rightitem;
    }
    
    
}
-(void)setupview{
    //初始化搜索框
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 64, XHScreenwidth, 56)];
    UISearchBar *search=[[UISearchBar alloc]initWithFrame:CGRectMake(10, 10, XHScreenwidth-20, 36)];
    search.backgroundImage=[UIImage imageWithStretchableName:@"searchbar_textfield_background"];
    search.placeholder=@"可输入车型、价格、颜色、配置..";
    [view addSubview:search];
    [self.view addSubview:view];
    //初始化导航栏右侧按钮
    [self setupRight:NO];
    //初始化scrollview
    UIScrollView *scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 156, XHScreenwidth, XHScreenheight-156)];
    
    scrollview.backgroundColor=[UIColor redColor];
    scrollview.contentSize=CGSizeMake(XHScreenwidth*4, XHScreenheight-156);
    [self.view addSubview:scrollview];
    self.scrollview=scrollview;
    self.scrollview.pagingEnabled=YES;
    self.scrollview.showsHorizontalScrollIndicator=NO;
    self.scrollview.showsVerticalScrollIndicator=NO;
    self.scrollview.bounces=NO;
    
    
}
-(void)toolbarmenuclick:(UIButton *)btn{
    NSLog(@"btntag---%ld",btn.tag);
}

-(void)postcar{
    NSLog(@"发车源");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
